package yc.star.common.controller;


import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.PageInfo;
import yc.star.common.domain.AppResult;
import yc.star.common.domain.TableDataInfo;

import java.util.List;

public class BaseController {

    public AppResult<Void> toAppResult (int rows) {

        if (rows > 0) {
            return AppResult.success();
        }
        return AppResult.failed();

    }

    public AppResult<Void> toAppResult (boolean result) {

        return result ? AppResult.success() : AppResult.failed();

    }

    public TableDataInfo getTableDataInfo (List<?> list) {
        if (CollectionUtil.isEmpty(list)) {
            return TableDataInfo.empty();
        }
        long total = new PageInfo<>(list).getTotal();
        return TableDataInfo.success(list,total);
    }

}